#include "strategy.h"

typedef struct {
    int my_total;
    int opponent_total;
} State;

int pick_coins(int round_id, int initial_coins, int opponent_last_pick, void *state_memory, size_t state_size) {
    State *state = (State*)state_memory;
    if (round_id == 1) {
        state->my_total = 0;
        state->opponent_total = 0;
    }
    state->opponent_total += opponent_last_pick;
    int remaining = initial_coins - (state->my_total + state->opponent_total);
    if (remaining <= 0) return 1;

    int pick = remaining % 4;
    if (pick == 0) pick = 3;
    if (pick > remaining) pick = remaining;
    if (pick < 1) pick = 1;

    state->my_total += pick;
    return pick;
}
